#import "GameOverScreen.h"
#import "State.h"
#import <QuartzCore/QuartzCore.h>
@implementation GameOverScreen

@synthesize player;


- (id)initWithFrame:(CGRect)frame{
	if(self=[super initWithFrame:frame]){
		startTime = CACurrentMediaTime();
        self.image=[UIImage imageNamed:@"screen_gameover.png"];
		NSArray* fa=[NSArray arrayWithObjects:
					 [UIImage imageNamed:@"countdown_10.png"],
					 [UIImage imageNamed:@"countdown_9.png"],
					 [UIImage imageNamed:@"countdown_8.png"],
					 [UIImage imageNamed:@"countdown_7.png"],
					 [UIImage imageNamed:@"countdown_6.png"],
					 [UIImage imageNamed:@"countdown_5.png"],
					 [UIImage imageNamed:@"countdown_4.png"],
					 [UIImage imageNamed:@"countdown_3.png"],
					 [UIImage imageNamed:@"countdown_3.png"],
					 [UIImage imageNamed:@"countdown_2.png"],
					 [UIImage imageNamed:@"countdown_1.png"],
					 nil];
		selection=[[Sprite alloc ]initWithArray:fa mirror:false];
		[selection setPosition:0 y:360];
		state=S_GAMEOVER;
	}
	return self;
}

-(void) action:(int)x y:(int) y {
	if (x < 160){
		[selection setPosition:20 y:380];
		state=S_TITLE;
	}
	else{
		[selection setPosition:180 y:380];
		state=S_PLAY;
	}
}

-(void) paintScreen{
	[self.image drawAtPoint:CGPointMake(0,0)];
	if(player!=nil)
		[player paint];
	[selection paint];
}
-(int) stateMachine {
	double x = CACurrentMediaTime();
	//x=x-startTime;
	int i = (int)(x-startTime) ;
	[selection setCurrentFrame:i];
	if (i>10) {
		state=S_TITLE;
	}
	return state;
}
@end